package com.sxhalo.fsms.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.sxhalo.fsms.util.TokenUtil;
import com.sxhalo.fsms.util.CookieUtils;

@Component
public class CommonInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2) {
		resp.setHeader("Access-Control-Allow-Origin", "*");
		resp.setHeader("Access-Control-Allow-Headers", "x-requested-with,x-auth-token");
		resp.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE");
		String token = CookieUtils.getCookieValue(req, "token");
		return TokenUtil.verifyToken(token);
	}
}
